import {Component, Input, OnInit, ViewEncapsulation} from '@angular/core';
import {HomepageService} from "../homepage.service";
import {Router} from "@angular/router";
import {Subscription} from "rxjs/Subscription";
import {ToolsService} from "@shared/service/tools/tools.service";
import {ImageServeService} from "@shared/service/image/image-serve.service";
import {Observable} from "rxjs/Observable";


@Component({
  selector: 'person-events',
  templateUrl: './homepage-events.component.html',
  styleUrls: ['./homepage-events.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class HomepageEventsComponent implements OnInit {
  subscription: Subscription = new Subscription();
  public defaultPicture: string;
  public nowdate: number;
  public eventList: Observable<any>;

  @Input() userId: string;

  constructor(public router: Router,
              public homepageService: HomepageService,
              public ToolServices: ToolsService,
              private imgService: ImageServeService) {
    this.defaultPicture = this.imgService.getSmallArticleImgHolder();
    this.eventList = this.homepageService.getevent;
  }

  TipCommon() {
    this.ToolServices.presentConfirm('下载求苗APP，看更多精彩内容!');
  }

  routerDetail(itemId) {
    this.router.navigate([`/match/detail`, itemId]);
  }

  /**
   * @description 获取赛事状态图标
   * @param img
   * @author baoww765
   * @date 2017-12-16
   */
  getIcon(img) {
    return this.imgService.getIcon(img);
  }

  /**
   * @description 判断赛事状态
   * @author baoww765
   * @date 2017-12-17
   * @param status
   * */
  /*checkMatchStatus(status) {
    return status === 3 ? this.getIcon('event_preheating.png') : status === 4 ? this.getIcon('event_ongoing.png') :
      (status === 5 ? this.getIcon('event_end.png') :
        (status === 6 ? this.getIcon('event_ongo.png') : status === 7 || status === 8 ? this.getIcon('event_finished.png') : ' '));

  }*/
    checkMatchStatus(status) {
      const status_list = 'preheating,ongoing,end,ongo,finished'.split(',');
      return this.getIcon('event_' + status_list[status - 3] + '.png');
    }

  ngOnInit() {
    this.nowdate = new Date().getTime();
  }

}

